package roles

import (
	"context"
	"xagent/internal/actors"
	proto "xagent/proto/v1"
)

// Architect represents the system architect role
type Architect struct {
	*actors.BaseAgent
	ctx context.Context
}

// NewArchitect creates a new architect agent
func NewArchitect() *Architect {
	baseAgent := actors.NewBaseAgent(
		"architect",
		"Responsible for system architecture and design decisions",
	)
	return &Architect{
		BaseAgent: baseAgent,
		ctx:       context.Background(),
	}
}

// ProcessTask handles architecture specific tasks
func (a *Architect) processTask(msg interface{}) {
	switch t := msg.(type) {
	case *proto.Task:
		if t.Name == "SystemDesign" {
			a.createSystemDesign(t)
		} else if t.Name == "APIDesign" {
			a.createAPIDesign(t)
		}
	}
}

// createSystemDesign generates system architecture design
func (a *Architect) createSystemDesign(task *proto.Task) {
	response := &proto.AgentMessage{
		Id:   task.Id,
		Type: proto.MessageType_MESSAGE_TYPE_RESPONSE,
		Content: &proto.AgentMessage_Message{
			Message: "System architecture design completed",
		},
		Metadata: map[string]string{
			"type":   "system_design",
			"status": "completed",
		},
	}

	if parent := a.GetContext().Parent(); parent != nil {
		a.GetContext().Send(parent, response)
	}
}

// createAPIDesign generates API design
func (a *Architect) createAPIDesign(task *proto.Task) {
	response := &proto.AgentMessage{
		Id:   task.Id,
		Type: proto.MessageType_MESSAGE_TYPE_RESPONSE,
		Content: &proto.AgentMessage_Message{
			Message: "API design completed",
		},
		Metadata: map[string]string{
			"type":   "api_design",
			"status": "completed",
		},
	}

	if parent := a.GetContext().Parent(); parent != nil {
		a.GetContext().Send(parent, response)
	}
}
